package com.logistics.material.controller;

import com.logistics.material.entity.model.MaterialBackSave;
import com.logistics.material.service.MaterialService;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/lgs/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    /**
     * 物料列表
     * @param code
     * @param pickStatus
     * @return
     */
    @GetMapping("list/{code}")
    public ResponseEntity list(@PathVariable("code") String code, @RequestParam(value = "pickStatus", required = false) String pickStatus)  throws MessageException{
        return ResponseUtil.success(materialService.materials(code, pickStatus));
    }

    /**
     * 查找库存物料
     * @param code
     * @return
     * @throws MessageException
     */
    @GetMapping("inventory/{code}")
    public ResponseEntity inventory(@PathVariable("code") String code) throws MessageException {
        return ResponseUtil.success(materialService.materials(code));
    }

    /**
     * 查找退料物料列表根据单据号
     * @param code
     * @return
     * @throws MessageException
     */
    @GetMapping("backs/{code}")
    public ResponseEntity materialBacks(@PathVariable("code") String code) {
        return ResponseUtil.success(materialService.materialBacks(code));
    }

    /**
     * 绑定物料
     * @param param
     * @return
     * @throws MessageException
     */
    @PutMapping("/bind")
    public ResponseEntity bind(@RequestBody MaterialBackSave param) throws MessageException{
        materialService.bind(param);
        return ResponseUtil.success();
    }

    /**
     * 解绑物料
     * @param station
     * @return
     * @throws MessageException
     */
    @DeleteMapping("/unbind/{station}")
    public ResponseEntity unbind(@PathVariable("station") String station) throws MessageException{
        materialService.unbind(station);
        return ResponseUtil.success();
    }
}
